// pages/exp/psi/precognition-result.js
var utils = require('../../../utils/util.js')
Page({
    /**
     * 页面的初始数据
     */
    data: {
        hitCount: 11,
        hitRate: '50.12%',
        myTotalTestCount: 2,
        myTotalHitRate: '50.102%',
        totalHitRate: '50.0002%'
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.attendID = options.attendID;
        var that = this
        utils.httpRequest({
            url: '/PsiPrecognition/result',
            data: { attendID: options.attendID },
            success: function (res) {
                if(res.data){
                    var d = res.data
                    var hitRate = (parseInt(d.hit_count) / 20).toFixed(4) +'%'
                    var myTotalHitRate = (parseInt(d.my_hit_count) / (parseInt(d.my_attend_count) * 20)).toFixed(6) + '%'
                    var totalHitRate = (parseInt(d.total_hit_count) / (parseInt(d.total_count))).toFixed(6) + '%'
                    that.setData({
                        hitCount: res.data.hit_count,
                        hitRate: hitRate,
                        myTotalTestCount: res.data.my_attend_count,
                        myTotalHitRate: myTotalHitRate,
                        totalHitRate: totalHitRate
                    })
                }
            }
        })
    },

    myExps: function () {
        wx.redirectTo({
            url: '../exp?showList=1',
        })
    },

    viewResult: function () {
        wx.redirectTo({
            url: 'precognition-result-all',
        })
    },

    again: function () {
        wx.redirectTo({
            url: 'precognition',
        })
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return { title: "超心理学测试：Precognition", path: '/pages/exp/psi/precognition', imageUrl: '../../../images/third-eye.jpg' }
    }
})